package com.myapp.ruyixing.http;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.myapp.ruyixing.model.ActivityInfo;
import com.myapp.ruyixing.model.ActivityInfo.InfoItem;

public class ActivityInfoParser extends RYJSONParser {
	@Override
	public Object parse(JSONObject jsonObject) {

		ActivityInfo actInfo = new ActivityInfo();
		actInfo.items = new ArrayList<ActivityInfo.InfoItem>();

		ModelParser.parseModel(actInfo, jsonObject);

		JSONObject data = jsonObject.optJSONObject("data");
		actInfo.aid = data.optString("aid", "");
		actInfo.datetime = data.optString("datetime", "");
		actInfo.num = data.optString("num", "");
		actInfo.originalprice = data.optString("originalprice", "");
		actInfo.presentprice = data.optString("presentprice", "");
		actInfo.picurl = data.optString("picurl", "");
		actInfo.title = data.optString("title", "");

		JSONArray list = data.optJSONArray("items");

		for (int i = 0; list != null && i < list.length(); i++) {
			JSONObject object = list.optJSONObject(i);
			if (object != null) {

				InfoItem item = new InfoItem();
				item.content = object.optString("content", "");
				item.title = object.optString("title", "");
				item.picurl = object.optString("picurl", "");
				actInfo.items.add(item);
			}
		}

		return actInfo;

	}
}
